1 package uba.db.jdbc;
2
3 import java.sql.DriverManager;
4 import java.sql.DriverPropertyInfo;
5 import java.util.Properties;
6
7 import junit.framework.TestCase;
8
9 /***
10 * @version $Revision: 1.1.1.1 $
11 */
12 public class DriverTest extends TestCase {
13 private static final String VALID_CONNECTION_URL = "localhost:1234";
14 private static final String VALID_JDBC_URL = "jdbc:ubadb://" + VALID_CONNECTION_URL;
15 private static final String INVALID_JDBC_URL = "jdbc:ubadb:localhost:1a34";
16 private static final int EXPECTED_MAJOR_VERSION = 0;
17 private static final int EXPECTED_MINOR_VERSION = 1;
18
19 private Driver driver;
20 private DriverPropertyInfo[] expectedPropertyInfo;
21 private SocketConnection expectedConnection;
22
23 protected void setUp() throws Exception {
24 expectedConnection = new SocketConnection();
25 expectedPropertyInfo = new DriverPropertyInfo[0];
26
27 MockConnectionFactory mockConnectionFactory = new MockConnectionFactory();
28 mockConnectionFactory.acceptsConnectionTo(VALID_CONNECTION_URL);
29 mockConnectionFactory.setCreateConnectionResult(expectedConnection);
30 mockConnectionFactory.setConnectionPropertiesInformation(expectedPropertyInfo);
31
32 driver = new Driver(mockConnectionFactory);
33 DriverManager.registerDriver(driver);
34 }
35
36 protected void tearDown() throws Exception {
37 DriverManager.deregisterDriver(driver);
38 }
39
40 public void testAcceptUrl() throws Exception {
41 assertTrue(driver.acceptsURL(VALID_JDBC_URL));
42 assertFalse(driver.acceptsURL(INVALID_JDBC_URL));
43 }
44
45 public void testGetPropertyInfo() throws Exception {
46 DriverPropertyInfo[] result = driver.getPropertyInfo(VALID_JDBC_URL, new Properties());
47
48 assertEquals(result.length, expectedPropertyInfo.length);
49 for (int i = 0; i < result.length; i++) {
50 assertEquals(result[i], expectedPropertyInfo[i]);
51 }
52 }
53
54 public void testGetMajorVersion() throws Exception {
55 assertEquals(driver.getMajorVersion(), EXPECTED_MAJOR_VERSION);
56 }
57
58 public void testGetMinorVersion() throws Exception {
59 assertEquals(driver.getMinorVersion(), EXPECTED_MINOR_VERSION);
60 }
61
62 public void testJdbcCompliant() throws Exception {
63 assertFalse(driver.jdbcCompliant());
64 }
65
66 public void testConnection() throws Exception {
67 java.sql.Connection con = DriverManager.getConnection(VALID_JDBC_URL);
68 assertEquals(con, expectedConnection);
69 con.close();
70 }
71 }